/**
 * 用户升级
 * @author yanwl
 * @date 2014-11-10
 */
$(function(){
	//升级去支付
	$('.upgrade').on('click',function(){
		var userNum = $(".dropbox_value").attr("data-value"),
			orderId = $('#orderId').val();
		location.href = "/myservice/order/toUpgradePayPage?orderId="+orderId+"&userNum="+userNum;
	});
	
	//下拉框样式
	$(".dropbox").dropBox({
	   width: 100,         //控件宽度,默认单位px
	   height: 20,         //控件高度,默认单位px
	   sltheight: 100      //下拉框最大高度,超出则出现滚动条,默认单位px
	});
});

//下拉框改变时计算价格
$(document).on('select_loaded',function(){
	/*价格计算*/
	$('.dropbox').find('li').on('click',function(){
		var $parent = $(this).parents('.dropbox').prev(),
			baseUser = $('#baseUser').val(),
			accountNum = $(this).attr('data-value'),
			userSpace = accountNum - baseUser,
			basePrice = $('#basePrice').val(),
			useLife = $('#useLife').val(),
			proOverTime = new Date($('#proOverTime').val());
		var month = calculateMonth(new Date(),proOverTime,"returnMonth");
		
		//永久产品
		if(useLife == -1) {
			useLife = 1; 
		}else {
			useLife = 12; 
		}
		var price = parseFloat(basePrice / useLife * month * userSpace).toFixed(2);
    	$('.need2pay em').text(price);
	});
	$('.dropbox').find('li:first').triggerHandler("click");
})
